<?php
require_once ("../models/config.php");
if (!securePage(__FILE__)) {
	// Forward to index page
	addAlert("danger", "Whoops, looks like you don't have permission to view that page.");
	header("Location: ../index.php");
	exit();
}

setReferralPage(getAbsoluteDocumentPath(__FILE__));

include '../newlib.php';
$nav = 'nav-main.php';
include 'header.php';
include '../lib/AppScope.pre.php';
$theUser = $app->theUser;
?>
<div class='col-md-8'>
<h1>Programma kiezen</h1>
<?php
global $tmpConnection;
$stm = $tmpConnection->prepare('select * from live where id = (select max(id) from live)');
$stm->execute();
$rs = $stm->fetch(PDO::FETCH_ASSOC);
$liveOne = $rs["titel"];
$liveUser = $rs["user"];
$liveDatum = $rs["datum"];
echo "<p class=\"opm\">Nu op de " . $PRODUCTNAME . ": programma \"$liveOne\", live gezet d.d. $liveDatum door $liveUser.</p>";
$stm2 = $tmpConnection->prepare('select * from programs order by titel');
$stm2->execute();
echo "<form name=\"frmProg\" action=\"editprog.php\" method=\"post\">";
$tel = 0;
echo "<ul class='list-group'>";
while ($row = $stm2->fetch(PDO::FETCH_ASSOC)) {
	$tel++;
    $id = "rb" . $row['id'];
	if ($row['titel'] === $liveOne) {
        echo "<li class='list-group-item list-group-item-success'>";
        echo "<div class='input-group'>";
        echo "<span class='input-group-addon'>";
        echo "<input checked id='$id' type=\"radio\" name=\"program\" value=\"" . $row['id'] . "\">";
        echo "</span>";
        echo "<label for='$id' class='form-control label-success'>" . $row['titel'] . "</label>";
        echo "<span class='input-group-addon label-success'>live gezet d.d. $liveDatum door $liveUser.</span>";
        echo "</div>";
        echo "</li>";
	} else {
        echo "<li class='list-group-item'>";
        echo "<div class='input-group'>";
        echo "<span class='input-group-addon'>";
        echo "<input id='$id' type=\"radio\" name=\"program\" value=\"" . $row['id'] . "\">";
        echo "</span>";
        echo "<label for='$id' class='form-control label-default'>" . $row['titel'] . "</label>";
        echo "</div>";
        echo "</li>";
	}
}

?>
    <li class='list-group-item'>
        <div class="input-group">
            <span class="input-group-addon">
              	<input id='id-new' type="Radio" name="program" value="-1">
            </span>
            <input type="text" class="form-control" name="newname" value="" onclick="document.frmProg.program[<?=$tel?>].checked = true;">
            <label for='id-new' class="input-group-addon">Nieuw programma</label>
        </div>
    </li>
    </ul>
	<input role="button" class="btn btn-info" type="button" value="Selecteer" onclick="go();">
	</form>

    <br/>
    <div class="alert alert-info">
        <span class="glyphicon glyphicon-info-sign"></span>
        Het groen gemerkte programma is momenteel op de <?=$PRODUCTNAME?> te zien
    </div>

	<script language="JavaScript">
		function go() {
			selektie = false;
			for (t=0;t<=<?=$tel?>;t++) {
				if (document.frmProg.program[t].checked) selektie = true;
			}
			if (selektie) {
				if (document.frmProg.program[<?=$tel?>].checked && document.frmProg.newname.value == "") {
					alert("Vul eerst een naam van het nieuwe programma in.");
					document.frmProg.newname.focus();
				} else {
					document.frmProg.submit();
				}
			} else {
				alert("U heeft nog geen keuze gemaakt");
			}
		}
	</script>
</div>
<div class="col-md-4">
<br>&gt;&gt;&gt;&nbsp;<a href="archive.php"><font color="Black"><b>Archief van de <?=$PRODUCTNAME?></b></font></a>
<br>&gt;&gt;&gt;&nbsp;<a href="showlog.php"><font color="Black"><b>Logbestand van vandaag</b></font></a>
<br>&gt;&gt;&gt;&nbsp;<a href="showloglive.php"><font color="Black"><b>Logbestand live gezet</b></font></a>
<br><br><font color="red"><b>Berichten:</b></font><br>
<iframe src="about:blank" width="300" height="80" name="messageframe"></iframe>
<br>&gt;&gt;&gt;&nbsp;<a href="../action.php?command=msgcompose"><font color="Black"><b>Laat een bericht achter</b></font></a>

</div>
<?php include 'footer.php';?>